<template>
	<view class="bizPage">
		<status-bar title="文档管理" />
		<view class="padding20">
			<view class="search bgwhite d-flex a-center m-bot20">
				<text class="iconfont icon-sousuo color-333 m-right20"></text>
				<input class="flex-1 size26" v-model="fileName" placeholder="请输入文件夹名搜索" confirm-type="search" @blur="getList()" />
			</view>

			<tree :treeData="list" @node-click="handleNodeClick" />

			<up-empty :show="noData" mode="list" marginTop="100"></up-empty>
		</view>
		
		<tab-bar />
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { toUrl, Toast } from '@/utils/utils.js'
	import Http from '@/utils/request.js'
	import statusBar from '../components/statusBar.vue'
	import tabBar from '../components/tabBar.vue'
	import tree from './components/tree.vue'
	
	const list = ref([])
	const fileName = ref('')
	const noData = ref(false)

	onLoad(() => {
		getList()
	})

	const getList = () => {
		noData.value = false
		Http.post({
			url: '/hr/fileInfo/queryAllDir',
			data: {
				fileName: fileName.value
			}
		}).then(res => {
			if(res.code != 0) return Toast(res.msg)
			let result = res.data || []
			list.value = result.map(item => ({...item, top: true}))
			if(!list.value.length) noData.value = true
		})
	}

	const handleNodeClick = (item) => {
		if(item.children.length) return
		if(!item.permissions || !item.permissions.includes('view')) return Toast('暂无查看权限')
		toUrl('/bizPage/docs/fileList?dirId=' + item.id + '&title=' + item.name)
	}
</script>

<style lang="scss" scoped>
	.bizPage {
		min-height: 100vh;
		background: #F9F9F9;
	}
	.search {
		height: 66rpx;
		box-shadow: 0rpx 3rpx 4rpx 0rpx rgba(58,100,132,0.11);
		border-radius: 33rpx;
		padding: 0 20rpx;
	}
</style>
